<?php

$xml = simplexml_load_file('catalog.rdf');

$books = Array();

$count = 0;
foreach ($xml->xpath('//pgterms:etext') as $textNode) {
  $id = str_replace('etext', '', $textNode['rdf:ID']);
  $book = Array();

  $book['title'] = $textNode->{'pgterms:friendlytitle'};
  $book['id'] = $id;
  $book['description'] = $textNode->{'dc:title'};
  $book['description'] .= "\n" . $textNode->xpath('//dc:title//dcterms:ISO639-2//rdf:value');

  $books[$id] = $book;
  $count++;
  if ($count % 100 == 0) echo $count;
}

$count = 0;
foreach ($xml->xpath('//pgterms:file') as $file) {
  $id = str_replace('#etext', '', $file->{'dcterms:isFormatOf'});
  $file = Array();

  $file['url'] = $file['rdf:about'];
  $file['size'] = $file->{'dcterms:extent'};
  $file['type'] = $file->xpath('//dc:format//dcterms:IMT//rdf:value');

  $books[$id]['files'][] = $file;
  if ($count % 100 == 0) echo $count;
}

print_r($books[0]);

?>
